package example.documentbased.mainModule.models.mappers
{
	import example.documentbased.mainModule.models.doman.Document;
	import example.documentbased.mainModule.models.factories.ItemsFactory;
	import example.documentbased.mainModule.models.vo.DocumentVO;

	public class DocumentMapper
	{
		private var _factory:ItemsFactory;
		
		public function DocumentMapper(facttory:ItemsFactory) 
		{
			_factory = facttory;
		}
		
		public function fromDomain(value:Document):DocumentVO
		{
			return _factory.createDocumentVO(value.id, value.uid, 
				value.editorId, value.name, value.text, value.lazy);
		}
		
		public function fromDomainItems(items:Object):Array
		{
			const result:Array = []; 
			for each (var item:Document in items) 
			{
				result.push(fromDomain(item));
			}
			return result;
		}
		
		public function toDomain(value:DocumentVO):Document
		{
			return _factory.createDocument(value.id, value.uid, 
				value.editorId, value.name, value.text, value.lazy);
		}
		
		public function toDomainItems(items:Object):Array
		{
			const result:Array = []; 
			for each (var item:DocumentVO in items) 
			{
				result.push(toDomain(item));
			}
			return result;
		}
	}
}